﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using XYAC.Framework.MonitorTireMaterialOnline.Entities;
using XYAC.Framework.MonitorTireMaterialOnline.OracleRemoteDB;

namespace XYAC.Framework.MonitorTireMaterialOnline.LocalData.Models
{
    /// <summary>
    /// 本地中间库缓存表
    /// </summary>
    [Table("YB_LOT_INSPECT")]
    public class YB_LOT_INSPECT_Local : EntityBase<long>
    {
        public YB_LOT_INSPECT_Local() { }

        public YB_LOT_INSPECT_Local(YB_LOT_INSPECT local)
        {
            this.LJ_ID = local.ID;
            this.SERIAL_NUMBER = local.SERIAL_NUMBER;
            this.PART_NUMBER = local.PART_NUMBER;
            this.TIRE_PART_NUMBER = local.TIRE_PART_NUMBER;
            this.PLAN_DATE = local.PLAN_DATE;
            this.SHIFT = local.SHIFT;
            this.EQP = local.EQP;
            this.PLANID = local.PLANID;
            this.RECEIVE_DATE = local.RECEIVE_DATE;
            this.RECEIVE_FLAG = local.RECEIVE_FLAG;
            this.CREATION_DATE = local.CREATION_DATE;


        }
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long LJ_ID { get; set; } // NUMBER
        public string? SERIAL_NUMBER { get; set; } // VARCHAR2
        public string? PART_NUMBER { get; set; } // VARCHAR2
        public string? TIRE_PART_NUMBER { get; set; } // VARCHAR2
        public DateTime? PLAN_DATE { get; set; } // DATE
        public string? SHIFT { get; set; } // VARCHAR2
        public string? EQP { get; set; } // VARCHAR2
        public string? PLANID { get; set; } // VARCHAR2
        public DateTime? RECEIVE_DATE { get; set; } // DATE
        public string? RECEIVE_FLAG { get; set; } // VARCHAR2
        public DateTime? CREATION_DATE { get; set; } // DATE

        public bool RemoteSyncState { get; set; }
        public DateTime RemoteSyncDate { get; set; } = DateTime.Now;

        public string? RelateLocalData1 { get; set; }
        public string? RelateLocalData2 { get; set; }
        public string? RelateLocalData3 { get; set; }
        [NotMapped]
        public int LocalSyncState { get; internal set; }
        [NotMapped]
        [Obsolete("This property should not be used.", true)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Browsable(false)]
        [JsonIgnore]
        public override bool? IsDeleted { get; set; }


        /// <summary>
        /// 隐式转换：从 YB_LOT_INSPECT_Local 转换为 YB_LOT_INSPECT
        /// </summary>
        /// <param name="local"></param>
        public static implicit operator YB_LOT_INSPECT(YB_LOT_INSPECT_Local local)
        {
            return ConvertToRemote(local);
        }

        public static YB_LOT_INSPECT ConvertToRemote(YB_LOT_INSPECT_Local local)
        {
            return new YB_LOT_INSPECT
            {
                ID = local.ID,
                SERIAL_NUMBER = local.SERIAL_NUMBER,
                PART_NUMBER = local.PART_NUMBER,
                TIRE_PART_NUMBER = local.TIRE_PART_NUMBER,
                PLAN_DATE = local.PLAN_DATE,
                SHIFT = local.SHIFT,
                EQP = local.EQP,
                PLANID = local.PLANID,
                RECEIVE_DATE = local.RECEIVE_DATE,
                RECEIVE_FLAG = local.RECEIVE_FLAG,
                CREATION_DATE = local.CREATION_DATE
            };
        }

        /// <summary>
        /// 隐式转换：从 YB_LOT_INSPECT 转换为 YB_LOT_INSPECT_Local
        /// </summary>
        /// <param name="inspect"></param>
        public static implicit operator YB_LOT_INSPECT_Local(YB_LOT_INSPECT inspect)
        {
            return ConvertToLocal(inspect);
        }

        public static YB_LOT_INSPECT_Local ConvertToLocal(YB_LOT_INSPECT inspect)
        {
            return new YB_LOT_INSPECT_Local
            {
                LJ_ID = inspect.ID,
                SERIAL_NUMBER = inspect.SERIAL_NUMBER,
                PART_NUMBER = inspect.PART_NUMBER,
                TIRE_PART_NUMBER = inspect.TIRE_PART_NUMBER,
                PLAN_DATE = inspect.PLAN_DATE,
                SHIFT = inspect.SHIFT,
                EQP = inspect.EQP,
                PLANID = inspect.PLANID,
                RECEIVE_DATE = inspect.RECEIVE_DATE,
                RECEIVE_FLAG = inspect.RECEIVE_FLAG,
                CREATION_DATE = inspect.CREATION_DATE,

                // 如果需要，可以添加额外字段的默认值
                RemoteSyncState = false,
                RemoteSyncDate = DateTime.Now
            };
        }
    }
}
